
package com.iedu.demo.lgq.controller;

import com.iedu.demo.lgq.entity.Kuaidi100Delivery;
import com.iedu.demo.lgq.mapper.OrderMapper;
import com.iedu.demo.lgq.service.OrderService;
import com.iedu.demo.lgq.entity.TbOrder;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

@RestController
@RequestMapping("/payment")
@CrossOrigin
public class PaymentController {

    @Autowired
    private OrderService orderService;  // 注入 OrderService

    @Autowired
    private OrderMapper orderMapper;  // 注入 OrderMapper

    /**
     * 处理支付请求
     * @param orderId 订单ID
     * @return 返回支付处理结果
     */
    @PostMapping("/pay/{orderId}")
    @Operation(summary = "支付订单")
    public boolean processPayment(@PathVariable Integer orderId) {
        return orderService.processPayment(orderId);
    }

    }
       /* // 获取订单
        TbOrder order = orderMapper.findOrderById(orderId);
        if (order == null) {
            return false;  // 订单不存在
        }

        // 检查订单状态
        Integer status = order.getStatus();
        if (status == null || status != 1) {
            return false;// 状态为 null 或不是 1，表示订单已支付或已取消，不能再次支付

        }

        // 更新订单状态为已支付（假设2为已支付状态）并记录支付时间
        Date paymentTime = new Date();  // 当前时间作为支付时间
        int updated = orderMapper.updateOrderPayment(orderId, 2, paymentTime);  // 更新订单状态和支付时间

        return updated > 0;  // 判断是否更新成功
    }
}
*/

